/**
 * The MIT License	
 * 
 * Copyright (c) 2009 Ghost Interactive
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * ghostinteractive@gmail.com
 * http://ghostinteractive.net/blog
 * @author Jeremy brown
 */
package net.ghostinteractive.overlays
{
	import flash.events.*;
	import flash.geom.Point;

	public class RadialGate extends ProximityGate
	{
		// -- Protected
		protected var _radius	:Number;
		
		/**
		 * Constructor
		 * This sub-class of the ProximityGate defines a circular region of proximity
		 * 
		 * @param _initPosition A point object representing the epicenter of this proximity range relative to original image size
		 * @param _initRadius The distance from the center of the epicenter
		 * @param _initZoomMin Zoom levels below this value will cause gate to close
		 * @param _initZoomMax Zoom levels above this value will cause gate to close
		 */
		public function RadialGate( _initPosition:Point, _initRadius:Number,
									_initZoomMin:Number, _initZoomMax:Number )
		{
			_position 	= _initPosition;
			_radius 	= _initRadius;
			_zmin		= _initZoomMin;
			_zmax		= _initZoomMax;
		}
		
		/**
		 * Evaluate the passed distance and zoom to determine whether or not 
		 * to open or close the gate
		 */
		override public function update( center:Point, zoom:Number ):void
		{
			var dx:Number 		= Math.abs( center.x - _position.x );
			var dy:Number		= Math.abs( center.y - _position.y );
			var distance:Number	= Math.sqrt( ( dx * dx ) + ( dy * dy ) ); 
			
			if( distance <= _radius && zoomIsInRange( zoom ) ){
				setState( OPENED );
			} else {
				setState( CLOSED );
			}
		}
	}
}